package com.sanyang.pda.presenter;


import com.sanyang.pda.bean.ManualOutboundDetailBean;
import com.sanyang.pda.contract.ManualOutBoundDetailContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;
import com.wangshen.base.ui.mvp.base.refresh.BaseRecyclerRefreshPresenter;
import com.wangshen.base.ui.mvp.base.refresh.RequestCallback;

import java.util.List;

import io.reactivex.functions.Consumer;

public class ManualOutBoundDetailPresenter extends BaseRecyclerRefreshPresenter<ManualOutBoundDetailContract.View, ManualOutboundDetailBean> implements ManualOutBoundDetailContract.Presenter {
    private String deliveryNo;

    public ManualOutBoundDetailPresenter(String deliveryNo) {
        this.deliveryNo = deliveryNo;
    }

    @Override
    public void onRefresh(RequestCallback<ManualOutboundDetailBean> callback) {
        deliveryDetailed(getCurrentPage(),callback);
    }

    @Override
    public void onLoadMore(RequestCallback<ManualOutboundDetailBean> callback) {
        deliveryDetailed(getCurrentPage(),callback);
    }

    @Override
    public void deliveryDetailed(int pageNum, RequestCallback<ManualOutboundDetailBean> callback) {
        NetUtils.geApi().deliveryDetailed(pageNum,10,deliveryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<ManualOutboundDetailBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<ManualOutboundDetailBean>> listBaseRowsAppEntity) throws Exception {
                        callback.onSuccess(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        callback.onFail(throwable.getMessage());
                    }
                });
    }
}
